import CryptoJS from 'crypto-js';

export default {
  encrypt(message) {
    const AES = {
      Key: '1011121314151617',
      IV: '9181716151413121',
    };
    const KEY = CryptoJS.enc.Utf8.parse(AES.Key); // 16字节密钥
    const IV = CryptoJS.enc.Utf8.parse(AES.IV); // 16字节初始向量
    const encrypted = CryptoJS.AES.encrypt(message, KEY, {
      iv: IV,
      mode: CryptoJS.mode.CBC,
      padding: CryptoJS.pad.Pkcs7,
    });
    return encrypted.toString();
  },
  decrypt(ciphertext) {
    const AES = {
      Key: '1011121314151617',
      IV: '9181716151413121',
    };
    const KEY = CryptoJS.enc.Utf8.parse(AES.Key); // 16字节密钥
    const IV = CryptoJS.enc.Utf8.parse(AES.IV); // 16字节初始向量
    const decrypted = CryptoJS.AES.decrypt(ciphertext, KEY, {
      iv: IV,
      mode: CryptoJS.mode.CBC,
      padding: CryptoJS.pad.Pkcs7,
    });
    return CryptoJS.enc.Utf8.stringify(decrypted);
  },
};
